package com.cc.exception.handler;

import com.cc.exception.CustomException;
import com.cc.response.ServerResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    //处理自定义的异常
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public Object customHandler(CustomException e) {
        e.printStackTrace();
        return ServerResponse.failedMsg(400,"业务内部错误");
    }

    //其他未处理的异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object exceptionHandler(Exception e) {
        e.printStackTrace();
        return ServerResponse.failedMsg(500,"内部错误");
    }
}